<!--
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
-->
<!--
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
-->
<template>
  <div>
    <el-form
      :model="condition"
      label-width="80px"
      :inline="false"
      size="normal"
    >
      <el-row :gutter="20">
        <el-col :span="8" :offset="0">
          <el-form-item label="岗位名称">
            <el-input v-model="condition.jobName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0">
          <el-form-item label="岗位分类">
            <el-select
              v-model="condition.lv1"
              placeholder="请选择分类进行筛选"
              clearable
            >
              <el-option
                v-for="item in cfyList"
                :key="item.objectId"
                :label="item.name"
                :value="item.name"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0">
          <el-form-item>
            <el-button type="primary" @click="handleSearch">查询</el-button>
            <el-button>取消</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-table :data="jobList">
      <el-table-column prop="jobName" label="岗位名称"> </el-table-column>
      <el-table-column prop="salaryDesc" label="薪资范围"> </el-table-column>
      <el-table-column prop="cityName" label="城市"> </el-table-column>
      <el-table-column prop="lv1" label="分类"> </el-table-column>
      <el-table-column prop="jobDegree" label="学历要求"> </el-table-column>
      <el-table-column prop="jobExperience" label="工作经验"> </el-table-column>
      <el-table-column label="操作">
        <template #default>
          <el-button type="primary" size="small">编辑</el-button>
          <el-button type="danger" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      @current-change="handleChange"
    >
    </el-pagination>
  </div>
</template>

<script>
import { jobGet, classifyGet } from "@/api/job";
export default {
  data() {
    return {
      jobList: [],
      total: 0, //总数量
      condition: {
        jobName: "",
        lv1: "",
      },
      cfyList: [],
    };
  },
  created() {
    //首屏渲染岗位
    jobGet().then((res) => {
      console.log(res);
      let { results, count } = res.data;
      this.jobList = results;
      this.total = count;
    });
    //渲染分类列表
    classifyGet().then((res) => {
      this.cfyList = res.data.results;
    });
  },
  methods: {
    handleChange(page) {
      console.log(page);
      jobGet(page).then((res) => {
        let { results } = res.data;
        this.jobList = results;
      });
    },
    // 查询
    handleSearch() {
      // let cond = this.condition
      let cond = { ...this.condition }; //脱离引用关系
      for (let attr in cond) {
        //删除对象中值为空的字段
        if (cond[attr] == "") {
          delete cond[attr];
        }
      }
      jobGet(1, cond).then((res) => {
        this.jobList = res.data.results;
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
